package com.example.data;

import com.example.androidperformance.R;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class PhotoListAdapter extends ArrayAdapter<PhotoStory>
{
	private Context context;
	private PhotoList photoList;
	
	public PhotoListAdapter(Context context, int textViewResourceId)
	{
		super(context, textViewResourceId);
		this.context = context;
		photoList = new PhotoList(context);
	}
	
	@Override
	public int getCount()
	{
		return photoList.getStories().size();
	}
	
	@Override
	public PhotoStory getItem(int position)
	{
		return photoList.getStories().get(position);
	}
	
	@Override
	public long getItemId(int position)
	{
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		View v = LayoutInflater.from(context).inflate(R.layout.photo_story, parent, false);
		TextView tv = (TextView) v.findViewById(R.id.textView1);
		//ImageView iv = (ImageView) v.findViewById(R.id.imageView1);
		//iv.setImageResource(getItem(position).getPhoto());
		//tv.setCompoundDrawables(null, context.getResources().getDrawable(getItem(position).getPhoto()), null, null);
		Drawable d = context.getResources().getDrawable(getItem(position).getPhoto());
		d.setBounds(0, 0, 285, 423);
		tv.setCompoundDrawables(null, d, null, null);
		tv.setText(getItem(position).getDescription());
		
		return v;
	}
}
